home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / FLAMOOT.ZIP / VIDEO.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-11-01  |  14.0 KB  |  528 lines

  1. ;*********************
  2. ;* FLamoot VGA SetUp *
  3. ;*********************
  4. ;(C) Type One 1994 - TFL/TDV Prod.
  5. ; email: llardin@is2.vub.ac.Be
  6.  
  7. ;-----------------------------------------
  8. ; Déclaration modèle mémoire
  9. .386
  10. DGROUP GROUP _DATA,_BSS
  11. _TEXT  SEGMENT DWORD PUBLIC USE16 'CODE'
  12.        ASSUME CS:_TEXT,DS:DGROUP
  13. _TEXT  ENDS
  14. _DATA  SEGMENT DWORD PUBLIC USE16 'DATA'
  15. _DATA  ENDS
  16. _BSS   SEGMENT DWORD PUBLIC USE16 'BSS'
  17. _BSS   ENDS
  18. ;-----------------------------------------
  19.  
  20.  
  21. _DATA  SEGMENT
  22.  
  23. ;*** GFX-mode structure *** 
  24. mode RECORD hgh:5, ver:3, hor:3, col:2, adr:2
  25. ;
  26. ; rem:   hgh = line doubling factor
  27. ;        ver = 0 --> 350 lines display     hor = 0 --> 128 horiz width
  28. ;              1     400 big                     1     160 (7-mode)
  29. ;              2     400                         2     180 (7-mode like)
  30. ;              3     400 60hz                    3     256
  31. ;              4     448                         4     320
  32. ;              5     480                         5     360
  33. ;              6     512                         
  34. ;              7     540
  35. ;        col = 0 --> 256 colors display    adr = 0 --> planar scheme (X-mode)
  36. ;              1     16                          1 --> chained
  37. ;              2     4                           2 --> cga
  38. ;              3     text 16                     3 --> mono
  39. ;
  40. ; PS: if you choose a 16 colors display, the horiz width is doubled !!!!!
  41.  
  42. ;****** VGA vertical timings ******
  43.  
  44. ;--- settings for 350 lines ---
  45. vert350 LABEL BYTE
  46.  DB 0a0h   ; vertical clock (3c2h)
  47.  DW 0bf06h ; vertical total
  48.  DW 01f07h ; overflow reg.
  49.  DW 08310h ; vertical retrace start
  50.  DW 08511h ; vertical retrace end
  51.  DW 05d12h ; vert. disp. enable end
  52.  DW 06315h ; vertical blank start
  53.  DW 0ba16h ; vertical blank end
  54.  
  55. ;--- settings for 400 lines / full scan ---
  56. vert400b LABEL BYTE
  57.  DB 0a0h   ; vertical clock (3c2h)
  58.  DW 0bf06h ; vertical total
  59.  DW 01f07h ; overflow reg.
  60.  DW 09c10h ; vertical retrace start
  61.  DW 08e11h ; vertical retrace end
  62.  DW 08f12h ; vert. disp. enable end
  63.  DW 09615h ; vertical blank start
  64.  DW 0b916h ; vertical blank end
  65.  
  66. ;--- settings for 400 lines ---
  67. vert400 LABEL BYTE
  68.  DB 060h   ; vertical clock (3c2h)
  69.  DW 0bf06h ; vertical total
  70.  DW 01f07h ; overflow reg.
  71.  DW 09c10h ; vertical retrace start
  72.  DW 08e11h ; vertical retrace end
  73.  DW 08f12h ; vert. disp. enable end
  74.  DW 09615h ; vertical blank start
  75.  DW 0b916h ; vertical blank end
  76.  
  77. ;--- settings for 400 lines / 60hz ---
  78. vert400h LABEL BYTE
  79.  DB 0e0h   ; vertical clock (3c2h)
  80.  DW 0bf06h ; vertical total
  81.  DW 01f07h ; overflow reg.
  82.  DW 09c10h ; vertical retrace start
  83.  DW 08e11h ; vertical retrace end
  84.  DW 08f12h ; vert. disp. enable end
  85.  DW 09615h ; vertical blank start
  86.  DW 0b916h ; vertical blank end
  87.  
  88. ;--- settings for 448 lines ---
  89. vert448 LABEL BYTE
  90.  DB 0e0h   ; vertical clock (3c2h)
  91.  DW 00b06h ; vertical total
  92.  DW 03e07h ; overflow reg.
  93.  DW 0da10h ; vertical retrace start
  94.  DW 09c11h ; vertical retrace end
  95.  DW 0bf12h ; vert. disp. enable end
  96.  DW 0c715h ; vertical blank start
  97.  DW 00416h ; vertical blank end
  98.  
  99. ;--- settings for 480 lines ---
  100. vert480 LABEL BYTE
  101.  DB 0e0h   ; vertical clock (3c2h)
  102.  DW 00b06h ; vertical total
  103.  DW 03e07h ; overflow reg.
  104.  DW 0ea10h ; vertical retrace start
  105.  DW 08c11h ; vertical retrace end
  106.  DW 0df12h ; vert. disp. enable end
  107.  DW 0e715h ; vertical blank start
  108.  DW 00416h ; vertical blank end
  109.  
  110. ;--- settings for 512 lines ---
  111. vert512 LABEL BYTE
  112.  DB 0e0h   ; vertical clock (3c2h)
  113.  DW 02306h ; vertical total
  114.  DW 0b207h ; overflow reg.
  115.  DW 00a10h ; vertical retrace start
  116.  DW 0ac11h ; vertical retrace end
  117.  DW 0ff12h ; vert. disp. enable end
  118.  DW 00715h ; vertical blank start
  119.  DW 01a16h ; vertical blank end
  120.  
  121. ;--- settings for 540 lines ---
  122. vert540 LABEL BYTE
  123.  DB 0e0h   ; vertical clock (3c2h)
  124.  DW 03006h ; vertical total
  125.  DW 0f007h ; overflow reg.
  126.  DW 02010h ; vertical retrace start
  127.  DW 0a911h ; vertical retrace end
  128.  DW 01b12h ; vert. disp. enable end
  129.  DW 01f15h ; vertical blank start
  130.  DW 02f16h ; vertical blank end
  131.  
  132. ;****** VGA horizontal timings ******
  133.  
  134. ;--- settings for 128 pixels ---
  135. horiz128 LABEL BYTE
  136.  DB 03h    ; horizontal clock
  137.  DW 02d00h ; horiz. total
  138.  DW 01f01h ; horiz. disp. enable end
  139.  DW 02002h ; horiz. blank start
  140.  DW 09003h ; horiz. blank end
  141.  DW 02504h ; horiz. retrace start
  142.  DW 08d05h ; horiz. retrace end
  143.  DW 01013h ; offset/logical width
  144.  DW 00801h ; clock mode register (3c4h) (00901h)
  145.  
  146. ;--- settings for 160 pixels ---
  147. horiz160 LABEL BYTE
  148.  DB 03h    ; horizontal clock
  149.  DW 02d00h ; horiz. total
  150.  DW 02701h ; horiz. disp. enable end
  151.  DW 02802h ; horiz. blank start
  152.  DW 09003h ; horiz. blank end
  153.  DW 02b04h ; horiz. retrace start
  154.  DW 08005h ; horiz. retrace start
  155.  DW 01413h ; offset/logical width
  156.  DW 00801h ; clock mode register (3c4h) (00901h)
  157.  
  158. ;--- settings for 180 pixels ---
  159. horiz180 LABEL BYTE
  160.  DB 07h    ; horiz. clock (3c2h)
  161.  DW 03200h ; horiz. total
  162.  DW 02c01h ; horiz. disp. enable end
  163.  DW 02d02h ; horiz. blank start
  164.  DW 0b003h ; horiz. blank end
  165.  DW 02f04h ; horiz. retrace start
  166.  DW 0b405h ; horiz. retrace end
  167.  DW 01713h ; offset/logical width
  168.  DW 00801h ; clock mode register (3c4h) (00901h) 
  169.  
  170. ;--- settings for 256 pixels ---
  171. horiz256 LABEL BYTE
  172.  DB 03h    ; horizontal clock
  173.  DW 05f00h ; horiz. total
  174.  DW 03f01h ; horiz. disp. enable end
  175.  DW 04002h ; horiz. blank start
  176.  DW 08203h ; horiz. blank end
  177.  DW 04a04h ; horiz. retrace start
  178.  DW 09a05h ; horiz. retrace end
  179.  DW 02013h ; offset/logical width
  180.  DW 00001h ; clock register (3c4h) (00101h)
  181.  
  182. ;--- settings for 320 pixels ---
  183. horiz320 LABEL BYTE
  184.  DB 03h    ; horizontal clock
  185.  DW 05f00h ; horiz. total
  186.  DW 04f01h ; horiz. disp. enable end
  187.  DW 05002h ; horiz. blank start
  188.  DW 08203h ; horiz. blank end
  189.  DW 05404h ; horiz. retrace start
  190.  DW 08005h ; horiz. retrace end
  191.  DW 02813h ; offset/logical width
  192.  DW 00001h ; clock register (3c4h) (00101h)
  193.  
  194. ;--- settings for 360 pixels ---
  195. horiz360 LABEL BYTE
  196.  DB 07h    ; horizontal clock
  197.  DW 06b00h ; horiz. total
  198.  DW 05901h ; horiz. disp. enable end
  199.  DW 05a02h ; horiz. blank start
  200.  DW 08e03h ; horiz. blank end
  201.  DW 05e04h ; horiz. retrace start
  202.  DW 08a05h ; horiz. retrace end
  203.  DW 02d13h ; offset/logical width
  204.  DW 00001h ; clock register (3c4h) (00101h)
  205.  
  206. ;***** Settings for colors *****
  207. EVEN
  208. col256 LABEL BYTE
  209.  DW 04005h    ; mode register (3ceh)
  210.  DB 030h,061h ; mode control  (3c0h) 
  211.  
  212. col16 LABEL BYTE
  213.  DW 00005h    ; mode register (3ceh)
  214.  DB 030h,021h ; mode control  (3c0h)
  215.  
  216. col4 LABEL BYTE
  217.  DW 03005h    ; mode register (3ceh)
  218.  DB 030h,021h ; mode control  (3c0h)
  219.  
  220. text16 LABEL BYTE
  221.  DW 01005h    ; mode register (3ceh)
  222.  DB 030h,02ch ; mode control  (3c0h)
  223.  
  224. ;***** Adressing mode *****
  225. EVEN
  226. planar LABEL WORD
  227.  DW 00604h    ; unchain (3c4h)
  228.  DW 00014h    ; turn off dword mode
  229.  DW 0e317h    ; turn on byte mode
  230.  
  231. chained LABEL WORD
  232.  DW 00e04h    ; chain   (3c4h)
  233.  DW 04014h    ; turn on dword mode
  234.  DW 0a317h    ; turn off byte mode
  235.  
  236. cga LABEL WORD
  237.  DW 00204h    ;         (3c4h)
  238.  DW 00014h
  239.  DW 0a217h
  240.  
  241. herc LABEL WORD
  242.  DW 00604h    ;         (3c4h)  
  243.  DW 00014h
  244.  DW 0c217h
  245.  
  246. ;*** Tables ***
  247. Vertab LABEL WORD
  248.  DW OFFSET vert350, OFFSET vert400b, OFFSET vert400, OFFSET vert400h
  249.  DW OFFSET vert448, OFFSET vert480, OFFSET vert512, OFFSET vert540
  250. Hortab LABEL WORD
  251.  DW OFFSET horiz128, OFFSET horiz160, OFFSET horiz180, OFFSET horiz256
  252.  DW OFFSET horiz320, OFFSET horiz360
  253. Coltab LABEL WORD
  254.  DW OFFSET col256, OFFSET col16, OFFSET col4, OFFSET text16
  255. Adrtab LABEL WORD
  256.  DW OFFSET planar, OFFSET chained, OFFSET cga, OFFSET herc
  257.  
  258. _DATA  ENDS
  259.  
  260. ;-----------------------------------------
  261. _TEXT SEGMENT
  262.              PUBLIC _WaitVBL
  263.              PUBLIC _WaitHBL
  264.              PUBLIC _SetVGA
  265.  
  266. VSYNC MACRO          ; Om de VBL te wachten...
  267.       call _WaitVBL
  268.       ENDM
  269.  
  270. MPUSH   MACRO reg1:REQ,reg2:VARARG   ; Vive Y.Roggeman/Greg & ses Macros
  271.         push reg1                    ; recursives !!!!!!! yahouuuuu !!!
  272.         IFNB <reg2>
  273.         MPUSH reg2
  274.         ENDIF
  275.         ENDM
  276.  
  277. MPOP    MACRO reg1:REQ,reg2:VARARG   ; bis bis !!!
  278.         IFNB <reg2>                  ; type brol = record....
  279.         MPOP reg2                    ; donc ça fait 20 bytes !!!
  280.         ENDIF                        ; donc 1 word ....
  281.         pop reg1                     ; brol je dis struct !!!
  282.         ENDM
  283.  
  284.  
  285. ;*************************
  286. ;* Set Up VGA video mode *
  287. ;*************************
  288.  
  289. ALIGN
  290. EVEN
  291. _SetVGA PROC FAR
  292.  
  293.         push bp
  294.         mov  bp,sp
  295.  
  296.         MPUSH eax,bx,cx,dx,si,di,es
  297.  
  298.         mov  ax,13h                 ; let the BIOS start with
  299.         int  10h                    ; mode 13 : 320x200x256 chained 
  300.         VSYNC 
  301.  
  302.         mov  ax,WORD PTR ss:[bp+6]  ; take WORD param
  303.         cld
  304.  
  305.      ; Addressing mode
  306.         mov  bx,ax
  307.         push ax
  308.         and  bx,MASK adr            ; get adressing mode
  309.         shl  bx,1
  310.         mov  si,WORD PTR[Adrtab+bx] ; corresponding table
  311.         mov  dx,3c4h
  312.         lodsw           ; (1)         
  313.         mov  bl,ah                  ; chain/unchain (only 4 bits used)
  314.         out  dx,al
  315.         inc  dl
  316.         in   al,dx
  317.         and  al,0f0h   
  318.         and  bl,00fh
  319.         or   al,bl
  320.         out  dx,al
  321.         dec  dl
  322.         mov  dl,0d4h
  323.         lodsw           ; (2)    
  324.         mov  bl,ah                  ; dword mode on/off
  325.         out  dx,al
  326.         inc  dl
  327.         in   al,dx
  328.         and  al,080h
  329.         and  bl,060h    ; bits 5,6
  330.         or   al,bl
  331.         out  dx,al
  332.         dec  dl
  333.         outsw           ; (3)         byte mode on/off
  334.         pop  ax
  335.  
  336.      ; Color mode
  337.         mov  bx,ax
  338.         push ax
  339.         and  bx,MASK col            ; get color mode
  340.         shr  bx,col-1            
  341.         mov  si,WORD PTR[Coltab+bx] ; corresponding table       
  342.         mov  dl,0ceh
  343.         lodsw           ; (1)         display plane output
  344.         mov  bl,ah
  345.         out  dx,al
  346.         inc  dl
  347.         in   al,dx
  348.         and  al,08fh    ; bits 4,5,6   
  349.         or   al,bl
  350.         out  dx,al
  351.         dec  dl
  352.         mov  dl,0c0h
  353.         outsb           ; (2)         pixel panning compatibility + PCS
  354.         lodsb
  355.         mov  bl,al    
  356.         inc  dl      
  357.         in   al,dx
  358.         dec  dl
  359.         and  al,090h    ; bits 6,5,3,2,1,0
  360.         or   al,bl
  361.         out  dx,al
  362.         pop  ax   
  363.  
  364.       ; Modify CRTC registers
  365.         push ax 
  366.         mov  dl,0d4h
  367.         mov  al,11h                 ; cr11
  368.         out  dx,al                  ; current value
  369.         inc  dl                     ; point to data
  370.         in   al,dx                  ; get cr11 value
  371.         and  al,07fh                ; remove cr0-cr7
  372.         out  dx,al                  ; write protect
  373.         pop  ax 
  374.  
  375.       ; Horizontal parameters
  376.         mov  bx,ax
  377.         push ax
  378.         and  bx,MASK hor            ; get horizontal parameters
  379.         shr  bx,hor-1
  380.         mov  si,WORD PTR[Hortab+bx] ; corresponding table
  381.         mov  bl,BYTE PTR[si]        ; get horizontal clock
  382.         inc  si
  383.         mov  dl,0d4h
  384.         mov  cx,7
  385.         rep  outsw
  386.         mov  dl,0c4h
  387.         lodsw                       ; just OR the right bits
  388.         mov  bh,ah                  ; (clock doubling)
  389.         out  dx,al
  390.         inc  dl
  391.         in   al,dx
  392.         and  al,037h
  393.         or   al,bh
  394.         out  dx,al
  395.         pop  ax
  396.  
  397.       ; Vertical parameters
  398.         push ax
  399.         mov  cl,bl
  400.         mov  bx,ax
  401.         and  bx,MASK ver            ; get vertical parameters
  402.         shr  bx,ver-1
  403.         mov  si,WORD PTR[Vertab+bx] ; corresponding table
  404.         or   cl,BYTE PTR[si]        ; get vertical clock
  405.         inc  si         
  406.         mov  dl,0c4h                ; alter sequencer register
  407.         mov  ax,0100h               ; synchronous reset
  408.         out  dx,ax
  409.         mov  dl,0cch
  410.         in   al,dx                  ; read clock
  411.         and  al,033h
  412.         or   al,cl
  413.         mov  dl,0c2h
  414.         out  dx,al                  ; new clock
  415.         mov  dl,0c4h                ; sequencer again
  416.         mov  ax,0300h               ; restart sequencer
  417.         out  dx,ax                  ; running again
  418.         mov  dl,0d4h
  419.         outsw
  420.         outsw
  421.         outsw
  422.         lodsw      ; (1) VR End : bits 7,6,3,2,1,0
  423.         mov  cl,ah
  424.         out  dx,al
  425.         inc  dl
  426.         in   al,dx
  427.         and  al,030h
  428.         and  cl,0cfh
  429.         or   al,cl
  430.         out  dx,al
  431.         dec  dl  
  432.         outsw
  433.         outsw
  434.         lodsw      ; (3) End VBlank : bits 6,5,4,3,2,1,0
  435.         mov  cl,ah
  436.         out  dx,al
  437.         inc  dl
  438.         in   al,dx
  439.         and  al,07fh
  440.         or   al,cl
  441.         out  dx,al
  442.         pop  ax
  443.          
  444.       ; Line doubling
  445.         and  ax,MASK hgh
  446.         shr  ax,hgh                 ; cell height
  447.         mov  cl,al
  448.         mov  dl,0d4h
  449.         mov  al,009h
  450.         out  dx,al
  451.         inc  dl
  452.         in   al,dx
  453.         and  al,0e0h
  454.         or   al,cl
  455.         out  dx,al
  456.  
  457.         mov  dl,0c4h                ; Clear Vidmem
  458.         mov  ax,0f02h
  459.         out  dx,ax
  460.         mov  cx,16384
  461.         mov  ax,0a000h
  462.         mov  es,ax
  463.         xor  di,di
  464.         xor  eax,eax
  465.         rep  stosd
  466.          
  467.  
  468.         MPOP eax,bx,cx,dx,si,di,es 
  469.  
  470.         leave
  471.         retf
  472.  
  473. _SetVGA ENDP
  474.  
  475. ;*************************
  476. ;* Wait Vertical Retrace *
  477. ;*************************
  478. ALIGN
  479. EVEN
  480. _WaitVBL PROC FAR
  481.  
  482.          MPUSH ax,dx
  483.  
  484.          mov  dx,3dah  ; Status Register
  485. EVEN
  486. @@:      in   al,dx
  487.          test al,08    ; bit 3
  488.          jnz  @B
  489. EVEN
  490. @@:      in   al,dx
  491.          test al,08
  492.          jz   @B
  493.  
  494.          MPOP ax,dx
  495.  
  496.          retf
  497.  
  498. _WaitVBL ENDP
  499.  
  500. ;***************************
  501. ;* Wait Horizontal Retrace *
  502. ;***************************
  503. ALIGN
  504. EVEN
  505. _WaitHBL PROC FAR
  506.  
  507.          MPUSH ax,dx
  508.  
  509.          mov  dx,3dah  ; Status Register
  510. EVEN
  511. @@:      in   al,dx
  512.          test al,01    ; bit 0
  513.          jnz  @B
  514. EVEN
  515. @@:      in   al,dx
  516.          test al,01
  517.          jz   @B
  518.  
  519.          MPOP ax,dx
  520.  
  521.          retf
  522.  
  523. _WaitHBL ENDP
  524.  
  525. _TEXT ENDS
  526.  
  527.       END
  528.